package cn.itsource.product.service.impl;

import cn.itsource.basic.query.BaseQuery;
import cn.itsource.basic.service.impl.BaseServiceImpl;
import cn.itsource.product.domain.Product;
import cn.itsource.product.domain.ProductDetail;
import cn.itsource.product.mapper.ProductDetailMapper;
import cn.itsource.product.mapper.ProductMapper;
import cn.itsource.product.service.IProductService;
import cn.itsource.utils.PageList;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class ProductServiceImpl extends BaseServiceImpl<Product> implements IProductService {

    @Autowired
    private ProductMapper productMapper;

    @Autowired
    private ProductDetailMapper detailMapper;

    @Override
    public void saveOrUpdate(Product product) {
        //先保存Product
        if (product.getId()==null){
            productMapper.save(product);
            //保存详情
            ProductDetail detail = product.getDetail();
            detail.setProduct_id(product.getId());
            detailMapper.save(detail);
        }else {
            productMapper.update(product);
            detailMapper.update(product.getDetail());
        }

    }

    @Override
    public void onSale(Long[] ids) {
        productMapper.onSale(ids);
    }

    @Override
    public Product detail(Long id) {
        return productMapper.detail(id);
    }
}
